package com.flash.InventoryManagement.controller;

import com.flash.GlobalManagement.util.Dbutil;
import com.flash.GlobalManagement.util.TableIdUtil;
import com.flash.GlobalManagement.util.TableNameUtil;
import com.flash.GlobalManagement.util.TableTimeUtil;
import com.flash.InventoryManagement.entity.CashStock;
import com.flash.InventoryManagement.entity.SecurityStock;
import com.flash.InventoryManagement.service.CashStockService;
import com.flash.InventoryManagement.service.SecurityStockService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author jr
 * @version 1.0
 * @date 2022/8/22
 */
@Controller
public class CashStockContrller {

    @Resource
    CashStockService cashStockService;
    @Resource
    Dbutil dbutil;

    @RequestMapping("selectCashStock")
    @ResponseBody
    public Map selectCashStock(CashStock cashStock, int page, int limit) {
        System.out.println("查询现金库存");
        Map map = new HashMap();
        List cashStocklist = cashStockService.selectCashStock(cashStock, page, limit);
        //记录总条数
        int count = cashStockService.countCashStock();
        map.put("code", 0);
        map.put("msg", "");
        map.put("count", count);
        map.put("data", cashStocklist);
        return map;
    }

    @RequestMapping("insertCashStock")
    @ResponseBody
    public String insertCashStock(CashStock cashStock){


        System.out.println("增加现金库存");
        cashStock.setCashStockId(dbutil.getMaxId3(TableIdUtil.CSID,TableNameUtil.CS,TableTimeUtil.CSTime,cashStock.getDateCashStock()));
        int i = cashStockService.insertCashStock(cashStock);
        System.out.println(i);
        if (i>0){
            return "增加成功";
        }else {
            return "增加失败";
        }
    }

    @RequestMapping("deleteCashStock")
    @ResponseBody
    public  String deleteCashStock(CashStock cashStock){
        System.out.println("删除现金库存");
        int i = cashStockService.deleteCashStock(cashStock);
        if (i>0){
            return "删除成功";
        }else {
            return "删除失败";
        }
    }

    @RequestMapping("updateCashStock")
    @ResponseBody
    public String updateCashStock(CashStock cashStock){
        System.out.println("修改现金库存");
        int i = cashStockService.updateCashStock(cashStock);
        if (i>0){
            return "增加成功";
        }else {
            return "增加失败";
        }
    }

}
